#pragma once
#include <SFML\Graphics.hpp>
#include <vector>
#include <string>
#include <iostream>

#define FRAME_COUNT 10
#define SPRITE_SHEET_COUNT 10

namespace game
{

	class SpriteSheetManager
	{
		std::vector<sf::Sprite*>  _sprite;/*[SPRITE_SHEET_COUNT];*/
		std::vector<sf::Texture*> _texture;/*[SPRITE_SHEET_COUNT];*/
		std::vector<unsigned int> _spacing;/*[SPRITE_SHEET_COUNT];*/
		std::vector<unsigned int> _idWidth;/*[SPRITE_SHEET_COUNT];*/
	public:
		unsigned int getSheetIndexWidth(int sheetId){return _idWidth.at(sheetId);}
		unsigned int getSheetSpacing(int sheetId)	{return _spacing.at(sheetId);}
		sf::Sprite * getSprite(int sheetId)			{return _sprite.at(sheetId);}
		sf::Texture* getTexture(int sheetId)		{return _texture.at(sheetId);}

		SpriteSheetManager()
		{
			_sprite.reserve(SPRITE_SHEET_COUNT);
			_texture.reserve(SPRITE_SHEET_COUNT);
			_spacing.reserve(SPRITE_SHEET_COUNT);
			_idWidth.reserve(SPRITE_SHEET_COUNT);
		}

		~SpriteSheetManager()
		{
			std::cout << "deleting spritesheet" <<std::endl;
			const int size = _sprite.size();
			for (int i =0; i < size; i++)
			{
				if (_sprite[i])
					delete _sprite[i];
				if (_texture[i])
					delete _texture[i];
			}
			//delete & _sprite;
			//delete &_texture;
		}
		void LoadSheet(std::string path, unsigned int pSpacing, unsigned int pXCount, int id)
		{
			if (id < SPRITE_SHEET_COUNT)
			{
				sf::Texture * txt = new sf::Texture;
				txt->loadFromFile(path);
				_texture.push_back(txt);
				_sprite.push_back(new sf::Sprite(*txt));
				_spacing.push_back(pSpacing);
				_idWidth.push_back(pXCount);
			}
			else
			{
				std::cout<<"Increase SPRITE_SHEET_COUNT"<<std::endl;
			}
		}
	};
}